package com.pureman.androidapp.network;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import com.pureman.androidapp.MainApplication;
import com.pureman.androidapp.utils.LogUtils;

import java.util.ArrayList;

public class NetWorkBroadcastReceiver extends BroadcastReceiver {

    public static ArrayList<NetWorkEventHandler> mListeners = new ArrayList<NetWorkEventHandler>();
    private static String NET_CHANGE_ACTION = "android.net.conn.CONNECTIVITY_CHANGE";

    @Override
    public void onReceive(Context context, Intent intent) {
        LogUtils.i("NetBroadcastReceiver-->onReceive");
        if (intent.getAction().equals(NET_CHANGE_ACTION)) {
            MainApplication.mNetWorkState = NetWorkUtil.getNetworkState(context);
            if (mListeners.size() > 0)// 通知接口完成加载
                for (NetWorkEventHandler handler : mListeners) {
                    handler.onNetWorkChange();
                }
        }
    }

    public static abstract interface NetWorkEventHandler {

        public abstract void onNetWorkChange();
    }
}
